import mongoose from 'mongoose'
const OnlineProducts = mongoose.model('OnlineProducts')

export const ProductPriceCountCheck = (count, productId, price) => {
  return new Promise((resolve, reject) => {
    OnlineProducts.findById(productId).then(currentProduct => {
      let param = ''
      switch (Number(price)) {
        case 1:
          param = 'oneYuanCount'
          break
        case 100:
          param = 'oneHundredYuanCount'
          break
        case 1000:
          param = 'oneThousandYuanCount'
          break
      }
      if (currentProduct[param] === count) {
        resolve(true)
      } else {
        reject(new Error(-103)) // 规格错误
      }
    })
  })
}
